import 'package:flutter/material.dart';
import 'package:flutter_mode/zyj/model/user.dart';
import 'package:flutter_mode/zyj/redux/main_redux.dart';
import 'package:flutter_mode/zyj/ui/banner.dart';
import 'package:flutter_mode/zyj/ui/draggable.dart';
import 'package:flutter_mode/zyj/ui/future_builder.dart';
import 'package:flutter_mode/zyj/ui/gaussian_blur.dart';
import 'package:flutter_mode/zyj/ui/image_picker.dart';
import 'package:flutter_mode/zyj/ui/inherited_widget.dart';
import 'package:flutter_mode/zyj/ui/login.dart';
import 'package:flutter_mode/zyj/ui/notification.dart';
import 'package:flutter_mode/zyj/ui/permission.dart';
import 'package:flutter_mode/zyj/ui/scoped.dart';
import 'package:flutter_mode/zyj/ui/stagger_animation.dart';
import 'package:flutter_mode/zyj/ui/stream_counter.dart';
import 'package:flutter_mode/zyj/ui/theme_test.dart';
import 'package:flutter_mode/zyj/ui/webview.dart';
import 'package:flutter_mode/zyj/utils/eventbus.dart';
import 'package:flutter_redux/flutter_redux.dart';

class MyAppZYJ extends StatelessWidget {
  // This widget is the root of your application.

  /*@override
  Widget build(BuildContext context) {
    return StoreProvider<UserState>(
      store: store,
      child: MaterialApp(
        theme: ThemeData(
          primarySwatch: Colors.green,
        ),
        home: MainPage(),
      ),
    );
  }*/
  @override
  Widget build(BuildContext context) {
    return MainPage();
  }
}

class MainPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _MainPage();
  }
}

class _MainPage extends State<MainPage> {
  @override
  void initState() {
    super.initState();
    bus.on("tap", (msg) {
      print(msg);
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("AppBar"),
        centerTitle: true,
      ),
      body: ListView(
        children: <Widget>[
          StoreConnector<MainRedux, User?>(
            converter: (store) => store.state.user,
            builder: (context, model) {
              return Center(
                child: Text(
                  model?.accountName ?? "未登录",
                  style: Theme.of(context).textTheme.bodyLarge,
                ),
              );
            },
          ),
          item(context,"交错动画", Icons.accessibility, StaggerAnimPage()), //交错动画
          item(context,"ThemeTest", Icons.theaters, ThemeTest()), //单个路由换肤
          item(context,"Notification", Icons.notifications, NotificationPage()), //通知
          item(context,"Login", Icons.phone_android, HeroPage()),
          item(context,"InheritedWidget", Icons.date_range, MyTree()), //数据共享
          item(context,"scoped_model", Icons.dashboard, CounterApp()), //数据共享
          // item(context,"banner", Icons.picture_as_pdf, BannerPage()),//banner
          item(context,"image_picker", Icons.image, ImagePickerPage()),//拍照、相册
          item(context,"Draggable", Icons.favorite, DraggablePage()),
          item(context,"StreamBuilder", Icons.style, CounterPage()),
          item(context,"FutureBuilder", Icons.ac_unit, FutureBuilderPage()),
          item(context,"WebView", Icons.web, WebViewPage(title: "测试",url: "https://www.baidu.com",)),
          item(context,"Gaussian blur", Icons.blur_on, GaussianBlurPage()),
          item(context,"permission_handler", Icons.perm_contact_calendar, PermissionPage()),
        ],
      ),
    );
  }

  Widget item(BuildContext context,String title, IconData iconData, Widget widget) {
    return Column(
      children: <Widget>[
        Container(
          child: ListTile(
            leading: Icon(iconData),
            title: Text(title),
            trailing: Icon(Icons.keyboard_arrow_right),
            onTap: () {
              Navigator.push(
                  context, MaterialPageRoute(builder: (context) => widget));
//              Navigator.of(context, rootNavigator: true)
//                  .push(MaterialPageRoute(builder: (context) => widget));
              bus.emit("tap", title);
            },
          ),
          color: Colors.white,
        ),
        Divider(height: 1),
      ],
    );
  }
}
